<template>
  <div>
    <!--查询参数-->
    <params
      ref="params"
      @handleRefresh="handleRefresh"
      :loading="loading"
    ></params>
    <!--表格页面-->
    <my-table
      ref="myTable"
      :dataSource="dataSource"
      :columns="columns"
      :loading="loading"
      :hasPage="false"
      @handleAdd="handleAdd"
      @removeSubmit="removeSubmit"
      @handleEdit="handleEdit"
      @handleImport="handleImport"
      @handleExport="handleExport"
      @handleDetail="handleDetail"
      @loadData="loadData"
      addAction="org_create"
      deleteAction="org_delete"
      editAction="org_edit"
      detailAction="org_details"
      importAction="org_import"
      exportAction="org_export"
    />
    <!--修改页面-->
    <modify
      v-if="modifyEntity.showModify"
      @handleRefresh="handleRefresh"
      :modifyEntity="modifyEntity"
    />
  </div>
</template>

<script>
import modify from "./modify";
import myTable from "_c/myTable/index";
import params from "./components/params";

import { orgColumns, queryOrg, deleteOrg } from "@/api/sys/identity/org";
export default {
  name: "Org",
  components: { params, modify, myTable },
  data() {
    return {
      modifyEntity: {
        // 传递的主键
        id: "",
        // 页面标题
        title: "",
        // 页面操作类型
        operation: "",
        // 是否展示编辑页面
        showModify: false,
      },
      // 加载动画
      loading: false,
      // 绑定的数据源
      dataSource: [],
      // 表格绑定的列
      columns: orgColumns,
    };
  },
  mounted() {
    this.loadData();
  },
  methods: {
    //#region 查询列表
    // 保存/修改后刷新表格
    handleRefresh() {
      this.modifyEntity.showModify = false;
      this.$refs.myTable.pagination.current = 1;
      this.loadData();
    },
    // 加载数据
    loadData() {
      this.loading = true;

      let that = this;
      queryOrg(this.$refs.params.params)
        .then((res) => {
          that.dataSource = res.data;
          that.loading = false;
        })
        .catch(() => {
          that.loading = false;
        });
    },
    //#endregion

    //#region 添加
    // 打开添加页面
    handleAdd() {
      this.modifyEntity = {
        title: "新增组织部门",
        showModify: true,
        operation: this.operationFlag.Add,
      };
    },
    //#endregion

    //#region 删除
    // 删除
    removeSubmit(ids) {
      deleteOrg(ids).then((res) => {
        if (res.code==200) {
          this.$notification.success({ description: res.msg });
          this.handleRefresh();
        } else {
          this.$notification.error({ description: res.msg });
        }
      });
    },
    //#endregion

    //#region 修改
    // 打开编辑页面
    handleEdit(item) {
      this.modifyEntity = {
        id: item.id,
        title: "修改组织部门",
        showModify: true,
        operation: this.operationFlag.Edit,
      };
    },
    //#endregion

    //#region 详情
    // 打开详情页面
    handleDetail(item) {
      this.modifyEntity = {
        id: item.id,
        title: "组织部门详情",
        showModify: true,
        operation: this.operationFlag.Detail,
      };
    },
    //#endregion

    //#region 导入
    // 导入数据
    handleImport() {},
    //#endregion

    //#region 导出
    // 导出数据
    handleExport() {},
    //#endregion
  },
};
</script>


